#include "bms_utils.h"

int right_bound( uint16_t *nums, uint8_t start_pos, uint8_t end_pos, uint16_t target )
{
	uint16_t left = start_pos;
	uint16_t right = end_pos;
	
	while( left < right )
	{
		uint16_t mid = ( left + right ) / 2;
		
		if( nums[mid] == target )
		{
			left = left + 1;
		}
		else if( nums[mid] < target )
		{
			left = mid + 1;
		}
		else
		{
			right = mid;
		}
	}
	
	if( left - 1 < start_pos )
	{
		return -1;
	}
	return left - 1;
}
